<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <a-input placeholder="请输入客户名称" v-model="queryParam.name"></a-input>
              <!--              <JInput placeholder="请输入" v-model="queryParam.name"></JInput>-->
            </a-form-item>
          </a-col>
          <!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                      <a-form-item label="上级客户">
                        <j-search-select-tag placeholder="请选择上级客户" v-model="queryParam.parentCustomerId"
                                             dict="biz_customer,name,id" />
                      </a-form-item>
                    </a-col>-->
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户状态">
                <j-search-select-tag placeholder="请选择" v-model="queryParam.state" dict="customer_state" />
              </a-form-item>
            </a-col>
            <!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
                          <a-form-item label="客户阶段">
                            <j-search-select-tag placeholder="请选择客户阶段" v-model="queryParam.stage" dict="customer_stage" />
                          </a-form-item>
                        </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="负责人">
                <JSelectUserByDepCustom placeholder="请选择负责人" v-model="queryParam.directorIds"></JSelectUserByDepCustom>
              </a-form-item>
            </a-col>
            <!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">
                          <a-form-item label="协同人">
                            <j-search-select-tag placeholder="请选择协同人" v-model="queryParam.collaboratorIds"
                                                 dict="sys_user,username,id" />
                          </a-form-item>
                        </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户类型">
                <j-search-select-tag placeholder="请选择客户类型" v-model="queryParam.type" dict="customer_type" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户性质">
                <j-search-select-tag placeholder="请选择客户性质" v-model="queryParam.nature" dict="customer_nature" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户分级">
                <j-search-select-tag placeholder="请选择客户分级" v-model="queryParam.classification"
                                     dict="customter_classification" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="客户行业">
                <j-search-select-tag placeholder="请选择客户行业" v-model="queryParam.industry" dict="customter_industry" />
              </a-form-item>
            </a-col>

            <!--            <a-col :xl="10" :lg="11" :md="12" :sm="24">
                          <a-form-item label="创建时间">
                            <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间"
                                    class="query-group-cust" v-model="queryParam.crateTime_begin"></j-date>
                            <span class="query-group-split-cust"></span>
                            <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间"
                                    class="query-group-cust" v-model="queryParam.crateTime_end"></j-date>
                          </a-form-item>
                        </a-col>-->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator flex-liangtou">
      <div>
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
        <a-button type="primary" icon="download" @click="handleExportXls('客户管理')">导出</a-button>
        <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                  @change="handleImportExcel">
          <a-button type="primary" icon="import">导入</a-button>
        </a-upload>
        <!-- 高级查询区域 -->
        <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                       @handleSuperQuery="handleSuperQuery"></j-super-query>
        <a-dropdown v-if="selectedRowKeys.length > 0 && sign!=5" v-has="'customer:batch_delete'">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel">
              <a-icon type="delete" />
              删除
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作
            <a-icon type="down" />
          </a-button>
        </a-dropdown>
      </div>
      <div>
        <j-dict-select-tag placeholder="请选择归档" :value="filed" type="radioButton" dictCode="is_filed"
                           @change="filedChange" />
      </div>

    </div>

    <!-- table区域-begin -->
    <div>
      <div>
        <a-tabs :activeKey="tabIndex" @change="tabsChange">
          <a-tab-pane :key="item.key" :tab="item.tab" :force-render="index==item.key?true:false"
                      v-for="(item,index) in tabsArr"></a-tab-pane>

          <!--          <a-tab-pane key="1" tab="今日新增"></a-tab-pane>
                    <a-tab-pane key="2" tab="本周新增"></a-tab-pane>
                    <a-tab-pane key="3" tab="我负责的"></a-tab-pane>
                    <a-tab-pane key="4" tab="我协同的"></a-tab-pane>
                    <a-tab-pane key="5" tab="下属负责的"></a-tab-pane>
                    <a-tab-pane key="6" tab="下属协同的"></a-tab-pane>-->
        </a-tabs>
      </div>
      <a-table
        class="minH"
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="laoqu" slot-scope="text,record">
          <a-button size="small" @click="laoquThis(record)">捞取</a-button>
        </template>
        <template slot="cstatus" slot-scope="text,record">
          <div @click="typeChange(record.id)">
            <a-icon type="heart" theme="filled" style="color: #ff9f26;font-size: 20px;" v-if="text==1" />
            <a-icon type="heart" style="font-size: 20px;color: #c6c6c6" v-else />
          </div>

        </template>
        <template slot="isRemind" slot-scope="text,record">
          <div @click="changeIsRemind(record)" class="follow-list-con">
            <!--增加getPopupContainer方法来调整popover的css层级 同步调整css z-index-->
            <a-popover
              title="跟进提醒内容"
              v-if="text==1"
              trigger="click"
              placement="right"
              :getPopupContainer=" triggerNode => {
 		return triggerNode.parentNode
 	}"
            >
              <template slot="content">
                <FollowList ref="FollowList" @ok="loadList" @yincang="yincang"></FollowList>
              </template>
              <a>
                <a-icon type="bulb" theme="filled" style="color: #ff9f26;font-size: 20px;" />
              </a>
            </a-popover>
            <a-icon type="bulb" v-else style="font-size: 20px;color: #c6c6c6" />
          </div>


        </template>
        <template slot="type" slot-scope="text,record">
          <div class="table-warp">
            {{ record.telephones[0].typeText }}
            <!--            <a-popover trigger="click" class="chakanquanbu">
                          <template slot="content">
                            <a-table :columns="seecolumns" :data-source="record.telephones" size="small" bordered
                                     :pagination="false">

                            </a-table>
                          </template>
                          <a-button type="link">
                            查看全部
                          </a-button>
                        </a-popover>-->
          </div>
        </template>
        <template slot="phone" slot-scope="text,record">
          <div class="table-warp">
            {{ record.telephones[0].phone }}
            <a-popover trigger="click" class="chakanquanbu">
              <template slot="content">
                <a-table :columns="seecolumns" :data-source="record.telephones" size="small" bordered
                         :pagination="false">

                </a-table>
              </template>
              <a-button type="link">
                查看全部
              </a-button>
            </a-popover>
            <!--            <a class="chakanquanbu">查看全部</a>-->
          </div>
        </template>
        <template slot="importance" slot-scope="text,record">
          <div>
            <a-rate :value="text" disabled />
          </div>
        </template>
        <template slot="address" slot-scope="text,record">
          <div class="table-warp">
            <a-tooltip>
              {{ text }}
<!--              <template slot="title">-->
<!--                {{ area.getText(text) }}-->
<!--              </template>-->
<!--              {{ area.getText(text) }}-->
            </a-tooltip>

          </div>
        </template>
        <template slot="addressInfo" slot-scope="text,record">
          <div class="table-warp">
            <a-tooltip>
              <template slot="title">
                {{ text }}
              </template>
              {{ text }}
            </a-tooltip>
          </div>
        </template>
        <template slot="abbreviation" slot-scope="text,record">
          <!--          <span class="table-warp">{{ text }}</span>-->
          <div class="table-warp">
            <a-tooltip>
              <template slot="title">
                {{ text }}
              </template>
              {{ text }}
            </a-tooltip>
          </div>
        </template>
        <template slot="parentCustomerId_dictText" slot-scope="text,record">
          <div class="table-warp">
            <a-tooltip>
              <template slot="title">
                {{ text }}
              </template>
              <a @click="handleShangjiDetail(record)">{{ text }}</a>

            </a-tooltip>
          </div>
        </template>
        <template slot="name" slot-scope="text,record">
          <div class="table-warp">
            <a-tooltip>
              <template slot="title">
                {{ text }}
              </template>
              <a @click="handleDetail(record)" class="table-warp">
                <a-tag color="cyan" v-if="record.filed==1">
                  归
                </a-tag>
                {{ text }}</a>
            </a-tooltip>
          </div>

        </template>
        <!--============以下3个字段 判断v-if作用于联系人是空数组时，表格会显示移位异常所作的调整===============-->
        <template slot="cssname" slot-scope="text,record">
          <div v-if="record.contactss.length<=0">
            无
          </div>
          <div v-else>
            {{ record.contactss[0].name }}
          </div>
        </template>
        <template slot="csstype" slot-scope="text,record">
          <div v-if="record.contactss.length<=0">
            无
          </div>
          <div v-else>
            {{ record.contactss[0].telephones[0].typeText }}
          </div>
        </template>
        <template slot="cssphone" slot-scope="text,record">
          <div v-if="record.contactss.length<=0">
            无
          </div>
          <div class="table-warp" v-else>
            {{ record.contactss[0].telephones[0].phone }}
            <a-popover trigger="click" class="chakanquanbu">
              <template slot="content">
                <a-table :columns="seecolumns"
                         :data-source="record.contactss[0].telephones?record.contactss[0].telephones:[]" size="small"
                         bordered
                         :pagination="false">

                </a-table>
              </template>
              <a-button type="link">
                查看全部
              </a-button>
            </a-popover>
          </div>
        </template>
        <!--============以上3个字段 判断v-if作用于联系人是空数组时，表格会显示移位异常所作的调整===============-->
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <!--          <a-divider type="vertical" />
                    <a-dropdown>
                      <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                      <a-menu slot="overlay">
                        <a-menu-item>
                           <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                            <a>删除</a>
                          </a-popconfirm>
                        </a-menu-item>
                      </a-menu>
                    </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!--    底部按钮-->
    <div class="buttonStyle">
      <div class="ant-alert ant-alert-info flex-box">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a-divider class="btn" type="vertical" />
        <div v-if="sign==5">
          <a-button type="default" @click="huanyuan">还原</a-button>
          <a-popconfirm title="确定彻底删除该数据吗?" @confirm="() => chedishanchu()">
            <a-button type="danger">彻底删除</a-button>
          </a-popconfirm>

        </div>
        <div v-else-if="sign==2">
          <a @click="onClearSelected">清空</a>
          <a-button v-has="'customer:distribute'" type="default"
                    @click="MAction(false,'/customer/customer/updateDirectorIds',1,1260)">分配
          </a-button>
        </div>
        <div v-else>
          <a @click="onClearSelected">清空</a>
          <a-button v-has="'customer:distribute'" type="default"
                    @click="MAction(false,'/customer/customer/updateDirectorIds',1,1260)">分配
          </a-button>
          <a-button type="default" @click="MAction(false,'/customer/customer/updateCollaboratorIds',2,1260)">移交
          </a-button>
          <a-button type="default" @click="FollowRemind">跟进提醒</a-button>
          <a-button type="default" @click="showConfirm(selectedRowKeys)">退回公海池</a-button>
          <a-button type="default" @click="visitorPro(selectedRowKeys)">加入访客计划</a-button>
          <a-button type="default" @click="MAction(false,'/customer/customer/deleteUser',3,1260)">删除负责人</a-button>
          <a-button type="default" @click="MAction(true,'/customer/customer/updateByDirectorIds',4,1260)">添加协同人
          </a-button>
          <a-button type="default" @click="MAction(true,'/customer/customer/deleteUser',4,1260)">删除协同人</a-button>
          <!--        <a-button type="default" @click="MAction(true,'/customer/customer/saveUser',3,1260)">添加协同人</a-button>
                  <a-button type="default" @click="MAction(true,'/customer/customer/deleteUser',4,1260)">删除协同人</a-button>-->
          <a-button type="danger" @click="updateFile(1)" v-if="isFiledButtonShow">归档</a-button>
          <a-button type="danger" @click="updateFile(2)" v-else>取消归档</a-button>
          <!--        <a-button type="default" @click="ctrStatus(selectedRowKeys)">客户动态</a-button>--></div>

      </div>
    </div>
    <customer-modal ref="modalForm" @ok="modalFormOk"></customer-modal>
    <visitor-program-modal ref="visitorForm" @ok="modalFormOk"></visitor-program-modal>
    <FollowRemindModal ref="FollowRemindModal" @ok="modalFormOk"></FollowRemindModal>
    <ctr-state-modal ref="ctrstateForm"></ctr-state-modal>
    <JSelectUserByDepModalCustom ref="MAmodel" :modalWidth="MAwidth" :multi="MAisMulti"
                                 @ok="MACallback"></JSelectUserByDepModalCustom>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { deleteAction, getAction } from '@api/manage'
import { postAction } from '@api/manage'
import CustomerModal from './modules/CustomerModal.Style#Drawer'
import VisitorProgramModal from './modules/VisitorProgramModal.Style#Drawer'
import CtrStateModal from './modules/CtrStateModal.Style#Drawer'
import JSelectUserByDepModalCustom from '@/components/jeecgbiz/modal/JSelectUserByDepModalCustom'
import JSelectUserByDepCustom from '@/components/jeecgbiz/JSelectUserByDepCustom'
import { message } from 'ant-design-vue/es'
import Area from '@/components/_util/Area'
import JInput from '@comp/jeecg/JInput'
import FollowRemindModal from '@/components/FollowRemind/modules/FollowRemindModal.Style#Drawer'
import FollowList from '@/components/FollowRemind/modules/FollowList'

export default {
  name: 'CustomerList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CustomerModal,
    VisitorProgramModal,
    FollowRemindModal,
    CtrStateModal,
    JSelectUserByDepModalCustom,
    JSelectUserByDepCustom,
    JInput,
    FollowList

  },
  data() {
    return {
      tabsArr: [
        {
          key: 0,
          tab: '全部'
        },
        {
          key: 1,
          tab: '今日新增'
        },
        {
          key: 2,
          tab: '本周新增'
        },
        {
          key: 3,
          tab: '我负责的'
        },
        {
          key: 4,
          tab: '我协同的'
        },
        {
          key: 5,
          tab: '下属负责的'
        },
        {
          key: 6,
          tab: '下属协同的'
        }
      ],
      tabIndex: 0,
      tabsPaneIndex: 0,
      disableMixinCreated: true,
      sign: '',//左侧子菜单标记值
      filed: 0,//搜索区 归档默认值
      tanVisible: false,
      followListShow: '',
      aaa: false,
      area: new Area(),
      //名单选择时 多选还是单选
      MAisMulti: false,
      //选择名单回调接口
      MAcallBackUrl: '',
      //名单参数类型    1===移交 2===负责人 3协同人 4===分配
      MAtype: 0,
      //弹框宽度
      MAwidth: 1260,
      isFiledButtonShow: true,//归档 取消归档按钮
      description: '客户管理页面',
      // 表头
      columns: [],
      columns_temp: [
        /* {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        }, */
        {
          title: '关注',
          align: 'center',
          dataIndex: 'cstatus',
          width: 50,
          scopedSlots: { customRender: 'cstatus' }
        },
        {
          title: '提醒',
          align: 'center',
          dataIndex: 'isRemind',
          width: 50,
          scopedSlots: { customRender: 'isRemind' }
        },
        {
          title: '操作',
          align: 'center',
          dataIndex: 'laoqu',
          width: 50,
          scopedSlots: { customRender: 'laoqu' }
        },
        {
          title: '客户名称',
          align: 'left',
          dataIndex: 'name',
          width: 150,
          scopedSlots: { customRender: 'name' }
        },
        /* {
          title: '上级客户',
          align: 'left',
          width: 150,
          dataIndex: 'parentCustomerId_dictText'
        }, */
        {
          title: '数量',
          align: 'left',
          width: 150,
          dataIndex: 'abbreviation',
          scopedSlots: { customRender: 'abbreviation' }
        },
        {
          title: '备注',
          align: 'center',
          width: 180,
          dataIndex: 'lossRemark'
        },

        {
          title: '负责人',
          align: 'left',
          width: 150,
          dataIndex: 'introduction'
        },
        /* {
          title: '客户电话',
          align: 'left',
          dataIndex: 'telephones',
          children: [
            {
              title: '类型',
              dataIndex: 'type',
              key: 'typeText',
              width: 150,
              align: 'left',
              scopedSlots: { customRender: 'type' }
            },
            {
              title: '号码',
              dataIndex: 'phone',
              key: 'phone',
              align: 'left',
              width: 150,
              scopedSlots: { customRender: 'phone' }
            }
          ]

        }, */
        {
          title: '电话',
          align: 'left',
          width: 150,
          dataIndex: 'address',
          scopedSlots: { customRender: 'address' }
        },
        {
          title: '地址详情',
          align: 'left',
          width: 150,
          dataIndex: 'addressInfo',
          scopedSlots: { customRender: 'addressInfo' }
        },
        {
          title: '客户状态',
          align: 'left',
          width: 150,
          dataIndex: 'state_dictText'
        },
        {
          title: '上级客户',
          align: 'left',
          width: 150,
          dataIndex: 'parentCustomerId_dictText',
          scopedSlots: { customRender: 'parentCustomerId_dictText' }
        },
        {
          title: '客户阶段',
          align: 'left',
          width: 150,
          dataIndex: 'stage_dictText'
        },
        /* {
          title: '流失原因',
          align: 'center',
          dataIndex: 'lossReasons_dictText'
        }, */
        /* {
          title: '流失备注',
          align: 'center',
          dataIndex: 'lossRemark'
        }, */

        /* {
          title: '负责人',
          align: 'left',
          width: 150,
          dataIndex: 'directorIds_dictText'
        }, */
        {
          title: '协同人',
          align: 'left',
          width: 150,
          dataIndex: 'collaboratorIds_dictText'
        },
        {
          title: '联系人',
          align: 'left',
          // width: 150,
          dataIndex: 'contactsIds_dictText',
          children: [
            {
              title: '姓名',
              width: 150,
              align: 'left',
              dataIndex: 'cssname',
              key: 'cssname',
              scopedSlots: { customRender: 'cssname' }
            },
            {
              title: '类型',
              width: 150,
              align: 'left',
              dataIndex: 'csstype',
              key: 'csstype',
              scopedSlots: { customRender: 'csstype' }
            },
            {
              title: '号码',
              align: 'left',
              width: 150,
              dataIndex: 'cssphone',
              key: 'cssphone',
              scopedSlots: { customRender: 'cssphone' }
            }
          ]
        },
        {
          title: '客户类型',
          align: 'left',
          width: 150,
          dataIndex: 'type_dictText'
        },
        {
          title: '客户性质',
          align: 'left',
          width: 150,
          dataIndex: 'nature_dictText'
        },
        {
          title: '客户分级',
          align: 'left',
          width: 150,
          dataIndex: 'classification_dictText'
        },
        {
          title: '客户行业',
          align: 'left',
          width: 150,
          dataIndex: 'industry_dictText'
        },
        {
          title: '重要程度',
          align: 'left',
          dataIndex: 'importance',
          width: 150,
          scopedSlots: { customRender: 'importance' }
        },
        {
          title: '客户来源',
          align: 'left',
          width: 150,
          dataIndex: 'source_dictText'
        },
        /* {
          title: '客户官网',
          align: 'center',
          dataIndex: 'website'
        }, */

        {
          title: '标签',
          align: 'left',
          width: 150,
          dataIndex: 'labelIds'
        },
        {
          title: '国家',
          align: 'left',
          width: 150,
          dataIndex: 'country'
        },
        /* {
          title: '归档',
          align: 'center',
          dataIndex: 'filed_dictText'
        }, */
        {
          title: '创建人',
          align: 'left',
          width: 150,
          dataIndex: 'createBy'
        },
        {
          title: '创建时间',
          align: 'left',
          width: 150,
          dataIndex: 'createTime'
        },
        {
          title: '更新时间',
          align: 'left',
          width: 150,
          dataIndex: 'updateTime'
        },
        /* {
          title: '最后跟进时间',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '分配时间',
          align: 'center',
          dataIndex: 'createBy'
        }, */
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        guanzhu: '/customer/customer/updateStatus',
        list: '/customer/customer/list',
        delete: '/customer/customer/delete',
        deleteBatch: '/customer/customer/deleteBatch',
        exportXlsUrl: '/customer/customer/exportXls',
        importExcelUrl: 'customer/customer/importExcel',
        updateCustomerGh: '/customer/customer/updateCustomerGh',//公海池
        updateDirectorIds: '/customer/customer/updateDirectorIds',//分配
        updateCollaboratorIds: '/customer/customer/updateCollaboratorIds',//移交
        saveUser: '/customer/customer/saveUser',//添加协同人
        deleteUser: '/customer/customer/deleteUser',//删除协同人
        updateCustomerDir: '/customer/customer/updateCustomerDir',//捞取
        deleteCustomer: '/customer/customer/deleteCustomer',//回收站彻底删除
        reductionCustomer: '/customer/customer/reductionCustomer'// 回收站 还原

      },
      dictOptions: {},
      superFieldList: [],
      CooperList: [],
      pcaData: '',
      seecolumns: [
        {
          title: '类型',
          dataIndex: 'typeText',
          align: 'center',
          key: 'typeText'
        },
        {
          title: '电话',
          dataIndex: 'phone',
          align: 'center',
          key: 'phone'
        }
      ],
      seedata: []
    }
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList()

  },
  mounted() {
    console.log('this.$route.path', this.$route.path)
    if (this.$route.path) {
      console.log('执行客户分类排查mounted')
      this.customerClassification(this.$route.path)
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  watch: {
    '$route': {
      deep: true,
      handler(newD, oldD) {
        console.log('newD', newD)
        console.log('oldD', oldD)
        if (newD.fullPath) {
          console.log('执行客户分类排查watch')
          this.customerClassification(newD.fullPath)
        }
      }
    }
  },
  methods: {
    changeTabsPaneIndex(index) {
      this.tabsPaneIndex = index
    },
    batchDel: function() {
      if (!this.url.deleteBatch) {
        this.$message.error('请设置url.deleteBatch属性!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认删除',
          content: '删除客户同时会删除销售机会、联系人、跟进记录、报价单、提醒等客户相关信息，存在合同的客户不允许删除！是否删除选中数据？',
          onOk: function() {
            that.loading = true
            deleteAction(that.url.deleteBatch, { ids: ids }).then((res) => {
              if (res.success) {
                //重新计算分页问题
                that.reCalculatePage(that.selectedRowKeys.length)
                that.$message.success(res.message)
                that.loadData()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.loading = false
            })
          }
        })
      }
    },
    //搜索框归档改变
    filedChange(e) {
      console.log('e', e)
      if (e == 1) {
        this.isFiledButtonShow = false
      } else {
        this.isFiledButtonShow = true
      }
      this.filed = e
      this.queryParam.filed = e
      this.loadData()
    },
    //客户分类排查
    customerClassification(path) {
      this.tabIndex = 0
      this.filed = 0
      this.selectedRowKeys = []
      let sign = path.split('_')[1]
      this.sign = sign
      console.log('sign', sign)
      //0是全部客户 查询基础列表
      if (sign == 0) {
        this.columns = this.columns_temp.filter(item => item.dataIndex !== 'laoqu')
        this.queryParam = {}
        this.loadData()
      } else if (sign == 2) {
        this.columns = this.columns_temp.filter(item => item.dataIndex !== 'isRemind' && item.dataIndex !== 'status' && item.dataIndex !== 'cstatus')
        //按菜单分类客户 ==重点==公海池==跟进==成交==回收站
        //公海池客户需要另外加载不同的columns表头配置
        // 控制客户经理列是否展示
        this.queryParam.status = sign
        this.loadData()
      } else if (sign == 5) {
        //客户回收站不显示关注和提醒
        this.columns = this.columns_temp.filter(item => item.dataIndex !== 'isRemind' && item.dataIndex !== 'cstatus' && item.dataIndex !== 'laoqu')
        this.queryParam.status = sign
        this.loadData()
      } else {
        this.columns = this.columns_temp.filter(item => item.dataIndex !== 'laoqu')
        this.queryParam.status = sign
        this.loadData()
      }

    },
    //捞取公海池客户
    laoquThis(record) {
      this.loading = true
      getAction(this.url.updateCustomerDir, { id: record.id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)

        }
      }).finally(() => {
        this.loading = false
        this.loadData()
      })
    },
    //归档
    updateFile(index) {
      // 1===归档  2===取消归档

      if (this.selectedRowKeys.length <= 0) {
        this.$message.error('请至少或者最多选择一条记录！')
        return
      }
      if (index == 1) {
        this.loading = true
        this.$confirm({
          title: '归档确定',
          content: (h) =>
            h('div', {}, [
              h('p', '归档客户为短时间内不需要跟进的客户，归档后不影响业务使用。'),
              h('p', '确定归档这 ' + this.selectedRowKeys.length + ' 位客户吗?')

            ]),
          /* content: '归档客户为短时间内不需要跟进的客户，归档后不影响业务使用。\n' + '\n' +
            '\n确定归档这 ' + this.selectedRowKeys.length + ' 位客户吗?', */
          okText: '确定',
          cancelText: '取消',
          onOk: () => {
            console.log('OK')
            let ids = this.selectedRowKeys.join(',')
            postAction('/customer/customer/updateFiled', { id: ids }).then(res => {
              console.log('归档', res)
              if (res.success) {
                this.$message.success(res.message)
              } else {
                this.$message.error(res.message)
              }
            }).finally(() => {
              this.loading = false
              this.loadData()
            })
          },
          onCancel: () => {
            this.loading = false
            console.log('Cancel')
          }
        })
      } else {
        this.loading = true
        this.$confirm({
          title: '归档取消',
          content: (h) =>
            h('div', {}, [
              // h('p', '归档客户为短时间内不需要跟进的客户，归档后不影响业务使用。'),
              h('p', '确定取消归档这 ' + this.selectedRowKeys.length + ' 位客户吗?')

            ]),
          okText: '确定',
          cancelText: '取消',
          onOk: () => {
            console.log('OK')
            let ids = this.selectedRowKeys.join(',')
            postAction('/customer/customer/updateCancelFiled', { id: ids }).then(res => {
              console.log('归档', res)
              if (res.success) {
                this.$message.success(res.message)
              } else {
                this.$message.error(res.message)
              }
            }).finally(() => {
              this.loading = false
              this.loadData()
            })
          },
          onCancel: () => {
            this.loading = false
            console.log('Cancel')
          }
        })
      }

    },
    /* initDictConfig() {
    }, */
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '客户名称', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'parentCustomerId',
        text: '上级客户',
        dictTable: 'biz_customer',
        dictText: 'name',
        dictCode: 'id'
      })
      fieldList.push({ type: 'string', value: 'abbreviation', text: '简介', dictCode: '' })
      fieldList.push({ type: 'string', value: 'telephoneIds', text: '客户电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'address', text: '地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'addressInfo', text: '地址详情', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'state',
        text: '客户状态(1潜在客户 2.初步客户 3.持续跟进 4.成交客户 5.忠诚客户 6.无效客户)',
        dictTable: '',
        dictText: '',
        dictCode: 'customer_state'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'stage',
        text: '客户阶段(1.发现需求 2.确认需求 3.解决方案 4.商务谈判 5.招投标 6.成交 7.流失)',
        dictTable: '',
        dictText: '',
        dictCode: 'customer_stage'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'lossReasons',
        text: '流失原因(1.竞品赢单 2.价格无法接受 3.决策者不支持 4.产品与业务不符 5.其他)',
        dictTable: '',
        dictText: '',
        dictCode: 'customer_loss_reasons'
      })
      fieldList.push({ type: 'string', value: 'lossRemark', text: '流失备注', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'directorIds',
        text: '负责人IDS',
        dictTable: 'sys_user',
        dictText: 'username',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'collaboratorIds',
        text: '协同人IDS',
        dictTable: 'sys_user',
        dictText: 'username',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'contactsIds',
        text: '联系人IDS',
        dictTable: 'sys_user',
        dictText: 'username',
        dictCode: 'id'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'type',
        text: '客户类型(1.最终客户 2.渠道客户 3.竞争对手)',
        dictTable: '',
        dictText: '',
        dictCode: 'customer_type'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'nature',
        text: '客户性质(1.企业客户 2.个人客户 3.政府事业单位)',
        dictTable: '',
        dictText: '',
        dictCode: 'customer_nature'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'classification',
        text: '客户分级(1.大型 2.中型  3.小型 4.微型)',
        dictTable: '',
        dictText: '',
        dictCode: 'customter_classification'
      })
      fieldList.push({
        type: 'sel_search',
        value: 'industry',
        text: '客户行业(1.金融 2.电信 3.教育 4.高科技 5.政府 6.制造业 7.服务业 8.能源 9.零售 10.媒体 11.娱乐 12.咨询 13.非盈利单位 14.公共事业 15.其他)',
        dictTable: '',
        dictText: '',
        dictCode: 'customter_industry'
      })
      fieldList.push({ type: 'int', value: 'importance', text: '重要程度(1-5)', dictCode: '' })
      fieldList.push({
        type: 'sel_search',
        value: 'source',
        text: '来源(1.网络推广 2.电话营销 3.渠道代理 4.其他)',
        dictTable: '',
        dictText: '',
        dictCode: 'customter_source'
      })
      fieldList.push({ type: 'string', value: 'website', text: '客户官网', dictCode: '' })
      fieldList.push({ type: 'string', value: 'introduction', text: '客户简介', dictCode: '' })
      fieldList.push({ type: 'string', value: 'labelIds', text: '标签IDS', dictCode: '' })
      fieldList.push({ type: 'string', value: 'country', text: '国家', dictCode: '' })
      fieldList.push({ type: 'int', value: 'filed', text: '归档(0.否 1.是)', dictCode: 'is_filed' })
      fieldList.push({ type: 'datetime', value: 'crateTime', text: '创建时间' })
      this.superFieldList = fieldList
    },
    MAction(MAisMulti, MAcallBackUrl, MAtype, MAwidth) {
      //Member action
      //设置多选还是单选
      // this.MAisMulti = false
      this.MAisMulti = MAisMulti
      //设置回调接口
      // this.MAcallBackUrl  = '/quotation/quotation/updateDirector'
      this.MAcallBackUrl = MAcallBackUrl
      //设置回调接口参数
      // this.MAtype = 1
      this.MAtype = MAtype
      //弹框宽度
      // this.MAwidth = 1260
      this.MAwidth = MAwidth
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请至少或者最多选择一条记录！')
        return
      }
      this.$refs.MAmodel.showModal()
    },
    //移交分配
    MACallback(e) {
      this.loading = true
      console.log('e', e)
      console.log('this.selectedRowKeys', this.selectedRowKeys)
      let ids = this.selectedRowKeys.join(',')
      let obj = {}
      if (this.MAtype == 1 || this.MAtype == 2) {
        obj = { id: ids, directorIds: e[0].id }
        //以下记录值重复 如需要 可放开
        /* switch (this.MAtype) {
          case 1://分配
            obj = { id: ids, directorIds: e[0].id }
            break
          case 2://移交
            obj = { id: ids, directorIds: e[0].id }
            break
        } */
        postAction(this.MAcallBackUrl, obj).then(res => {
          if (res.success) {
            this.selectedRowKeys = []
            this.$message.success(res.message)
            this.loading = false
            this.loadData()
          } else {
            this.$message.error(res.message)
            this.loading = false
          }
        })
      } else {
        switch (this.MAtype) {
          case 3://负责人
            /* let arr1 = []
            e.forEach(res=>{
              arr.push(res.id)
            }) */
            obj = { id: ids, directorIds: e[0].id }
            break
          case 4://协同人
            let arr2 = []
            e.forEach(res => {
              arr2.push(res.id)
            })
            obj = { id: ids, collaboratorIds: arr2.join(',') }
            break
        }
        postAction(this.MAcallBackUrl, obj).then(res => {
          if (res.success) {
            this.selectedRowKeys = []
            this.$message.success(res.message)
            this.loading = false
            this.loadData()
          } else {
            this.$message.error(res.message)
            this.loading = false
          }
        })
      }
    },
    //确认退回公海池
    showConfirm(id) {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warn('未选中任何客户信息')
        return
      }
      this.loading = true
      this.$confirm({
        title: '退回确认?',
        content: '把客户退回公海池同时会删除销售机会、联系人、跟进记录、报价单、提醒等客户相关信息，存在合同的客户不允许退回公海池！是否把选中数据退回公海池？',
        onOk: () => {
          console.log('确定')
          let ids = this.selectedRowKeys.join(',')
          getAction('/customer/customer/updateCustomerGh', { id: ids }).then(res => {
            if (res.success) {
              this.$message.success(res.message)
            } else {
              this.$message.error(res.message)
            }
          }).finally(() => {
            this.loading = false
            this.loadData()
          })
        },
        onCancel: () => {
          this.loading = false
          console.log('取消')
        },
        class: 'test'
      })
    },

    //加入访客计划
    visitorPro(id) {
      if (this.selectedRowKeys <= 0) {
        this.$message.warn('未选中任何客户信息')
        return
      }
      let visitorNameArr = []
      let customerIdArr = []
      this.dataSource.forEach(res => {
        if (this.selectedRowKeys.includes(res.id)) {
          visitorNameArr.push(res.name)
          customerIdArr.push(res.customerId)
        }
      })
      console.log('visitorNameArr', visitorNameArr)
      console.log('customerIdArr', customerIdArr)
      let record = {
        visitorNameArr: visitorNameArr,
        customerId: this.selectedRowKeys.join(','),
        customerIdArr: customerIdArr.join(',')
      }
      this.$refs.visitorForm.add(record)
    },

    //跟进提醒
    FollowRemind() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warn('请至少或者最多选择一条记录！')
        return
      }
      let followIdArr = []
      let customer_idArr = []
      this.dataSource.forEach(res => {
        if (this.selectedRowKeys.includes(res.id)) {
          followIdArr.push(res.name)
          customer_idArr.push(res.id)
        }
      })
      console.log('followIdArr', followIdArr)
      let record = {
        followIdArr: followIdArr,
        title: followIdArr[0] + '等' + followIdArr.length + '个客户的跟进提醒',
        numberType: '客户名称',
        type: 4,
        businessId: this.selectedRowKeys.join(','),
        customerId: customer_idArr.join(','),
        isAdd: true
      }
      this.$refs.FollowRemindModal.add(record)
      this.$refs.FollowRemindModal.followShow = true

    },

    //客户动态
    ctrStatus(id) {
      if (this.selectedRowKeys.length != 1) {
        this.$message.warn('请选择1条客户信息')
        return
      }
      this.$refs.ctrstateForm.edit(id)
      this.$refs.ctrstateForm.title = '客户动态'
      this.$refs.ctrstateForm.disableSubmit = false
    },
    handleEdit: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.dongtaiShow = false
      this.$refs.modalForm.width = 800

      this.$refs.modalForm.disableSubmit = false
    },
    handleAdd: function() {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.dongtaiShow = false
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.width = 800
    },
    handleDetail: function(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.dongtai(record.id)
      this.$refs.modalForm.title = '详情'
      this.$refs.modalForm.dongtaiShow = true
      this.$refs.modalForm.width = 1200

      this.$refs.modalForm.disableSubmit = true
    },
    //上级客户查看
    handleShangjiDetail(record) {
      this.loading = true

      getAction(this.url.list + '?id=' + record.parentCustomerId).then(res => {
        if (!res.result) {
          this.$message.error(res.message)
          return false
        }
        console.log(res.result)
        if (res.success) {
          this.$refs.modalForm.edit(res.result.records[0])
          this.$refs.modalForm.dongtai(record.parentCustomerId)
          this.$refs.modalForm.title = '详情'
          this.$refs.modalForm.dongtaiShow = true
          this.$refs.modalForm.width = 1200

          this.$refs.modalForm.disableSubmit = true
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.loading = false
      })

    },
    //关注
    typeChange(id) {
      this.loading = true
      getAction(this.url.guanzhu, { id: id }).then(res => {

        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.loading = false
        this.loadData()
      })
    },
    //提醒
    changeIsRemind(res) {
      console.log(res)
      //判断状态  标记isAdd是新增状态 需要在form里判断 是新增还是编辑
      if (res.isRemind == 0) {
        let record = {
          followIdArr: [res.name],
          title: res.name + '的客户跟进提醒',
          numberType: '客户名称',
          type: 4,
          businessId: res.id,
          customerId: res.id,
          isAdd: true
        }
        this.$refs.FollowRemindModal.add(record)
        this.$refs.FollowRemindModal.followShow = true
      } else {
        //弹出提醒列表
        let obj = Object.assign(res, { type: 4 })
        this.$refs.FollowList.getID(obj)

      }
    },
    //还原
    huanyuan() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warn('未选中任何数据！')
        return
      }
      this.loading = true
      postAction(this.url.reductionCustomer, { id: this.selectedRowKeys.join(',') }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.loading = false
        this.loadData()
      })
    },
    //跟进提醒的刷新列表
    loadList() {
      this.loadData()
    },
    //隐藏提醒列表
    yincang() {
      this.tanVisible = false
    },
    //tab页查询
    tabsChange(e) {
      this.tabIndex = e
      console.log(e)
      if (e == 0) {
        this.queryParam = {}
        this.loadData()
      } else {
        this.queryParam.statusTop = e
        this.loadData()
      }

    },
    //回收站彻底删除
    chedishanchu() {
      console.log(this.selectedRowKeys)
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warn('未选中任何数据！')
        return
      }
      this.loading = true
      deleteAction(this.url.deleteCustomer, { ids: this.selectedRowKeys.join(',') }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      }).finally(() => {
        this.loading = false
        this.loadData()
      })
    },
    //重置
    searchReset() {
      this.queryParam = {}
      this.queryParam.filed = this.filed
      this.queryParam.statusTop = this.tabIndex
      if (this.filed == 1) {
        this.isFiledButtonShow = false

      } else {
        this.isFiledButtonShow = true
      }
      this.loadData(1)
    }

  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';

.buttonStyle {

  button {
    margin-left: 10px;
  }
}

.ant-table table {
  table-layout: fixed;
}

.table-warp {
  width: 100%;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1; /* 这里是超出几行省略 */
  overflow: hidden;
  position: relative;
}

.chakanquanbu {
  transition: all 0.3s ease-out;
  opacity: 0;
  position: absolute;
  right: -16px;
  top: -4px;
  background: #e6f7ff;
}

/deep/ .ant-table-tbody > tr:hover > td {
  .chakanquanbu {
    opacity: 1;
  }
}

/*.follow-list-box {
  position: absolute;
  width: 300px;
  height: 200px;
  background: #00A0E9;
  right: -320px;
  top: 50%;
  transform: translateY(-50%);
}*/

.follow-list-con {
  position: relative;
}

/deep/ .ant-popover {
  z-index: 800 !important;
}

.flex-box {
  display: flex;
  flex-direction: row;
  align-items: center;
}

/*默认表格高度 撑起空白*/
/deep/ .minH .ant-table-body {
  min-height: 400px;
  //border-left: 1px solid #e8e8e8;
  //border-right: 1px solid #e8e8e8;
}

/deep/ .minH .ant-table-placeholder {
  display: none;
}

.flex-liangtou {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>